//
//  YGBarButtonItem+Extension.swift
//  sinaWeiBoGui
//
//  Created by liyonggui on 16/5/14.
//  Copyright © 2016年 liyonggui. All rights reserved.
//

import UIKit

/// UIBarButtonItem 的扩展
extension UIBarButtonItem {
    
    /// 便利构造函数, 在扩展中只能添加便利构造函数
    convenience init(imageName:String, target: AnyObject?, action: Selector) {
        let button = UIButton()
        
        button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.sizeToFit()
        
        // 点击事件
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        // 需要调用自己的指定构造函数
        self.init(customView:button)
    }
    
    
}

























